<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

// need to evolve search
if( $_GET["year_start"] AND $_GET["year_end"] )
{
	$year_start = strip_tags($_GET["year_start"]);	
	$year_end = strip_tags($_GET["year_end"]);
	
	file_put_contents  ( "params_search_date.txt", 
								"year_start '" .$year_start.
								"' year_end '" .$year_end."'");
	/*
	$query = new Doctrine_Query();
   	$query->from('FinTransactions')
				->where('deleted = 0 
						 AND t_date BETWEEN ($year_start, $year_end)
            	->orderby('year_start');
                  
   	$items = $query->execute();	   
   	file_put_contents  ( "select_by_centre.txt", $items);
	*/
}
else if ($_GET["profit_loss_id"]) 
{
	$profit_loss_id = strip_tags($_GET["profit_loss_id"]);	
	file_put_contents  ( "param_search_str.txt", $profit_loss_id);
	
	$query = new Doctrine_Query();
   	$query->from('FinTransactions')
				->where('deleted = 0 
							AND profit_loss_id ='.$profit_loss_id);
                  
   	$items = $query->execute();
   	file_put_contents  ( "select_by_centre.txt", $items);
}
else 
{	
	$query = new Doctrine_Query();
    $query->from('FinTransactions')
    			->where('deleted = 0')
            	->orderby('t_date');
                  
    $items = $query->execute();	
    file_put_contents  ( "select_all.txt", $items);
}
            
/// Return XML
$str.='<results>';
	foreach ($items as $item){
		$str.='<record>';
			$str.='<transaction_id>'.$item["transaction_id"].'</transaction_id>';
			$str.='<profit_loss_id>'.$item["profit_loss_id"].'</profit_loss_id>';
			$str.='<t_value>'.$item["t_value"].'</t_value>';
			$str.='<t_currency_id>'.$item["t_currency_id"].'</t_currency_id>';
			$str.='<t_date>'.$item["t_date"].'</t_date>';
			$str.='<created>'.$item["created"].'</created>';
		$str.='</record>';
	}
$str.='</results>';
   
header ("content-type: text/xml"); 
echo $str;

file_put_contents  ( "getAgent_Out.txt", $str);

?>